/*
* This class holds the game
* This class should take care of things such as timeing and controls
*/
#include "NumberMunchersGame.h"

#include <windows.h>
#include "GameScreen.h"
#include "ScreenManager.h"


NumberMunchersGame::NumberMunchersGame()
{
	dxEngine = CDirectXEngine::Instance();
	controls = Controls::Instance();
	gameRules = GameRules::Instance();

}

NumberMunchersGame::~NumberMunchersGame()
{
}

void NumberMunchersGame::Initialise(HINSTANCE hInstance, HWND hWnd )
{
	dxEngine->Initialise( hWnd, 800, 600 );
	controls->Initialise( hInstance, hWnd );
	gameRules->Initialise( MULTIPLES, 1, 50 );

	//currentScreen = new GameScreen(); //FIXME: Testing
}

void NumberMunchersGame::Clean()
{
//	delete currentScreen; //FIXME something not right here with the deletion

	dxEngine->Clean();
}
void NumberMunchersGame::Update(double frameTime)
{
	
	controls->CaptureKeys();

	if (frameTime == 0)
		frameTime = 0.010; //Timer resolution is crap so if we get 0ms set to 10ms (about the accurcy of the timer)

	ScreenManager * sm = ScreenManager::Instance();
	if( sm->HasScreenChanged() )
		currentScreen = sm->GetNewScreen();
	
	currentScreen->Update(frameTime);


}

void NumberMunchersGame::Draw()
{
	dxEngine->BeginScene();

	currentScreen->Draw();

	dxEngine->EndScene();
}

void NumberMunchersGame::SetScreen( Screen * newScreen )
{
	currentScreen = newScreen;
}
